//
//  HomeStatisticViewController.m
//  WheatPlan
//
//  Created by 王晨辉 on 15/5/26.
//  Copyright (c) 2015年 IOSTeam. All rights reserved.aaa
//

#import "HomeStatisticViewController.h"
#import "GrowthReportViewController.h"
#import "DripViewController.h"
#import "WorkViewController.h"
#import "PhotoViewController.h"
#import "ChildrenViewController.h"

@interface HomeStatisticViewController ()

@end

@implementation HomeStatisticViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    

    
    //设置导航栏头文字
    self.navigationItem.title = @"家园统合";
    //设置导航栏背景颜色
    [self.navigationController.navigationBar setBarTintColor:[GetFileModel colorWithHexString:@"#ff763a" alpha:1]];
    //设置导航栏字体颜色
    [self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],NSForegroundColorAttributeName,nil]];
    self.view.backgroundColor = [UIColor whiteColor];
    

    
    //自定义左右按钮
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setBackgroundImage:[UIImage imageNamed:@"_0000_返回.png"]
                      forState:UIControlStateNormal];
    [button addTarget:self action:@selector(turntolast)
     forControlEvents:UIControlEventTouchUpInside];
    button.frame = CGRectMake(0, 0, 20, 15);
    
    UIBarButtonItem *menuButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    
    self.navigationItem.leftBarButtonItem = menuButton;
    [MBProgressHUD showHUDAddedTo:self.view animated:YES];


    [self subView];
    

    
    // Do any additional setup after loading the view.
}

-(void)subView{
    
    
    int a =  self.navigationController.navigationBar.frame.size.height+20;
    
    ////NSLog(@"%d",a);
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *ID = [user objectForKey:@"ID"];


    NSDictionary *param = @{@"userId": ID};
    [UserDAL getHomeCollectionParams:param withBlock:^(NSDictionary *data, NSError *error) {
        
        [MBProgressHUD hideHUDForView:self.view animated:YES];
        
        
        ////NSLog(@"%@",data);
        
        if (data) {
            
            if (data.count!=0) {
                
                NSString * babyGrewUpImageURL = [data objectForKey:@"babyGrewUpImageURL"];
                NSString * babyInZoneURL = [data objectForKey:@"babyInZoneURL"];
                NSString * broadcast = [data objectForKey:@"broadcast"];
                
                ////NSLog(@"%@",broadcast);
                
                
                hornButton = [self BUttonFrame:CGRectMake(0, a, SCREEN_WIDTH, SCREEN_HEIGHT/19)  andAdd:nil andUlr:nil];
                [hornButton setImage:[UIImage imageNamed:@"_0001_iconfont-iconfontcolor34"] forState:UIControlStateNormal];
                
                UILabel * constLab = [self labelCreationUsingFrame:CGRectMake(SCREEN_HEIGHT/19+15, a, SCREEN_WIDTH, SCREEN_HEIGHT/19)  andFont:[UIFont systemFontOfSize:12] andText:[data objectForKey:@"broadcast"] andAlignMent:NSTextAlignmentLeft];
                ////NSLog(@"%@",constLab);
                
                
                
                thedoorButton = [self BUttonFrame:CGRectMake(17, a+SCREEN_HEIGHT/19*2, SCREEN_WIDTH-34, SCREEN_HEIGHT/3.2)  andAdd:@selector(gotoa) andUlr:babyGrewUpImageURL];
                
                _growUpLab = [self labelCreationUsingFrame:CGRectMake(0, a+SCREEN_HEIGHT/19*2+ SCREEN_HEIGHT/3.2, SCREEN_WIDTH, 34) andFont:[UIFont systemFontOfSize:16] andText:[data objectForKey:@"babyGrewUpTitle"] andAlignMent:NSTextAlignmentCenter];
                
                integrationButton = [self BUttonFrame:CGRectMake(17, a+SCREEN_HEIGHT/19*2+SCREEN_HEIGHT/3.2+34, SCREEN_WIDTH-34, SCREEN_HEIGHT/3.2)  andAdd:@selector(gotoView) andUlr:babyInZoneURL];
                
                _parkLab = [self labelCreationUsingFrame:CGRectMake(0, a+SCREEN_HEIGHT/19*2+ SCREEN_HEIGHT/3.2*2+34, SCREEN_WIDTH, 34) andFont:[UIFont systemFontOfSize:16] andText:[data objectForKey:@"babyInZoneTitle"] andAlignMent:NSTextAlignmentCenter];
                
                
                
            }else{
                
                
                
                UIAlertView * alertview = [[UIAlertView alloc] initWithTitle:@"提示" message:@"暂无家园统和信息" delegate:self cancelButtonTitle:@"确认" otherButtonTitles:nil, nil];
                [alertview show];
                

                

                
            }
            
            
            
        }
        
        
    }];
    
    

    
    
    
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    NSString *msg = [[NSString alloc] initWithFormat:@"您点击的是第%d个按钮!",buttonIndex];
    

    ////NSLog(@"msg:%@",msg);
    
    if (buttonIndex == 0) {
        
        
        [self dismissViewControllerAnimated:YES completion:nil];
        ////NSLog(@"1111111");
        
    }else if(buttonIndex == 1){
        
        ////NSLog(@"2222222");
        
        
    }
    
    
    
}








/**  创建BUtton*/
-(UIButton *) BUttonFrame:(CGRect)frame  andAdd:(SEL)str andUlr:(NSString *)urls{
    
    
    
    NSURL *url=[NSURL URLWithString:urls];
    NSData * data1=[NSData dataWithContentsOfURL:url];
    
    UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = frame;
//    [button setImage:[UIImage imageWithData:data1] forState:UIControlStateNormal];
    [button setBackgroundImage:[UIImage imageWithData:data1] forState:UIControlStateNormal];
    [button addTarget:self action:str forControlEvents:UIControlEventTouchUpInside];
    button.layer.masksToBounds = YES; //没这句话它圆不起来
    button.layer.cornerRadius = 6.0; //设置图片圆角的尺度
    [self.view addSubview:button];
    
    return button;
    
    
    
}


/**  创建Label*/
-(UILabel *) labelCreationUsingFrame:(CGRect) frame andFont:(UIFont *) font andText:(NSString *) text andAlignMent:(NSTextAlignment) alignment{
    
    
    UILabel *label_tmp = [[UILabel alloc] initWithFrame:frame];
    [label_tmp setFont:font];
    [label_tmp setText:text];
    [self.view addSubview:label_tmp];
    [label_tmp setTextAlignment:alignment];
    
    return label_tmp;
    
}



-(void)gotoa{
    
    
    ChildrenViewController * growthVC = [[ChildrenViewController alloc]init];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:growthVC];
    [self presentViewController:nav animated:YES completion:nil];
    
    
    
    
    
}
-(void)gotoView{
    
    
    PhotoViewController * dripVC = [[PhotoViewController alloc]init];
    UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:dripVC];
    [self presentViewController:nav animated:YES completion:nil];

    
    
}

-(void)turntolast{
    
    [self dismissViewControllerAnimated:YES completion:nil];
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
